package com.zm.demo.core.tcf;

class Solution {
    public int search(int[] nums, int target) {

        if(nums == null || nums.length == 0){
            return -1;
        }

        if(nums.length < 1){
            for(int i = 0 ; i<nums.length; i++){
                if(nums[i] == target){
                    return i;
                }else {
                    return -1;
                }
            }
        }


        return search(0, nums.length-1, nums, target);
    }

    int search(int min, int max, int[] nums, int target){
        int mid = min + (max-min)/2;
        while(min < max){
            if (nums[mid] < nums[mid-1]){
                if(nums[mid] < target){
                    return search(mid+1, max, nums, target) ^ search(0, mid-1, nums, target);
                }else if (nums[mid] > target){
                    return -1;
                }else{
                    return mid;
                }
            }
            if (nums[mid] > nums[mid+1]){
                if(nums[mid] < target){
                    return -1;
                }else if (nums[mid] > target){
                    return search(mid+1, max, nums, target) ^ search(0, mid-1, nums, target);
                }else{
                    return mid;
                }
            }

            mid = min + (max-min)/2;
        }

        int a = 'a' - 'b';
        System.out.println(a);
        return -1;
    }
}   